using System;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Nine;
using Nine.Components;
using Nine.Graphics;
using NG = Nine.Graphics;
using Nine.Physics;

using System.Collections.Generic;

namespace Sample {
  public class Sample : Microsoft.Xna.Framework.Game {
    private Scene scene;
    private Input input;

    public Sample() {      
      GraphicsDeviceManager graphics = new GraphicsDeviceManager( this );

      graphics.PreferMultiSampling = true;
      graphics.SynchronizeWithVerticalRetrace = false;
      graphics.PreferredBackBufferWidth = 1280;
      graphics.PreferredBackBufferHeight = 800;

      Window.AllowUserResizing = true;

      Content = new ContentLoader( Services );
      Content.RootDirectory = "Content";

      IsMouseVisible = true;
      IsFixedTimeStep = false;
    }

    protected override void LoadContent() {
      Components.Add( new FrameRate( GraphicsDevice, Content.Load<SpriteFont>( "Courier" ) ) );
      Components.Add( new InputComponent( Window.Handle ) );
      this.scene = Content.Load<Scene>( "sample" );

      input = new Input();
      input.MouseDown += ( sender, e ) => {
        if ( e.Button == MouseButtons.Left )
          ;
      };

      base.LoadContent();
    }

    protected override void Update( GameTime gameTime ) {
      if ( scene != null ) {
        scene.Update( (float)gameTime.ElapsedGameTime.TotalSeconds );
      }

      base.Update( gameTime );
    }

    protected override void Draw( GameTime gameTime ) {
      scene.Draw( GraphicsDevice, (float)gameTime.ElapsedGameTime.TotalSeconds );
      if ( Keyboard.GetState().IsKeyDown( Keys.Space ) ) {
        scene.DrawDiagnostics( GraphicsDevice, (float)gameTime.ElapsedGameTime.TotalSeconds );
        scene.DrawModelSkeletons( GraphicsDevice, (float)gameTime.ElapsedGameTime.TotalSeconds );
      }

      base.Draw( gameTime );
    }

    static void Main( string[] args ) {
      using ( Sample game = new Sample() ) {
        game.Run();
      }
    }
  }
}
